package com.qding.park.manager.adapter.factory;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import com.qding.park.manager.adapter.factory.enums.ParkAdapterEnum;
import com.qding.park.target.common.adapter.BaseDataAdapter;
import com.qding.park.target.common.adapter.CarAdapter;
import com.qding.park.target.common.adapter.InviteAdapter;
import com.qding.park.target.common.adapter.LockCarAdapter;
import com.qding.park.target.common.adapter.ParkAdapter;
import com.qding.park.target.common.adapter.PayFeeAdapter;
import com.qding.park.target.common.adapter.ReserveAdapter;

/**
 * @ClassName AdapterParkProxyJVMFactory
 * @Description TODO(以JVM内的方式实现 AdapterParkProxy 工厂实现)
 * @author Administrator
 * @Date 2016年8月24日 下午2:26:21
 * @version 1.0.0 依赖于 springcontext JVM环境
 */
@Component("adapterParkProxySpringContextJVMFactory")
public class AdapterParkProxySpringContextJVMFactoryImpl implements AdapterParkProxyFactory, ApplicationContextAware {

    protected ApplicationContext context;

    public void setApplicationContext(ApplicationContext arg0) throws BeansException {
        this.context = arg0;
    }

    @Override
    public BaseDataAdapter getBaseDataAdapter(String supplierId) {
        BaseDataAdapter resultObj = (BaseDataAdapter) context
                .getBean(ParkAdapterEnum.BASEDATE_ADAPTER_NAME.getValue() + "_" + supplierId);
        return resultObj;
    }

    @Override
    public InviteAdapter getInviteAdapter(String supplierId) {
        InviteAdapter resultObj = (InviteAdapter) context
                .getBean(ParkAdapterEnum.INVITE_ADAPTER_NAME.getValue() + "_" + supplierId);
        return resultObj;
    }

    @Override
    public LockCarAdapter getLockCarAdapter(String supplierId) {
        LockCarAdapter resultObj = (LockCarAdapter) context
                .getBean(ParkAdapterEnum.LOCKCAR_ADAPTER_NAME.getValue() + "_" + supplierId);
        return resultObj;
    }

    @Override
    public ParkAdapter getParkAdapter(String supplierId) {
        ParkAdapter resultObj = (ParkAdapter) context
                .getBean(ParkAdapterEnum.PARK_ADAPTER_NAME.getValue() + "_" + supplierId);
        return resultObj;
    }

    @Override
    public PayFeeAdapter getPayFeeAdapter(String supplierId) {
        PayFeeAdapter resultObj = (PayFeeAdapter) context
                .getBean(ParkAdapterEnum.PAYFEE_ADAPTER_NAME.getValue() + "_" + supplierId);
        return resultObj;
    }

    @Override
    public CarAdapter getCarAdapter(String supplierId) {
        CarAdapter resultObj = (CarAdapter) context
                .getBean(ParkAdapterEnum.CAR_ADAPTER_NAME.getValue() + "_" + supplierId);
        return resultObj;
    }

    @Override
    public ReserveAdapter getReserveAdapter(String supplierId) {
        ReserveAdapter resultObj = (ReserveAdapter) context
                .getBean(ParkAdapterEnum.RESERVE_ADAPTER_NAME.getValue() + "_" + supplierId);
        return resultObj;
    }

}
